package com.usian.admin.controller.v1;

import com.usian.common.aliyun.GreenImageScan;
import com.usian.common.aliyun.GreenTextScan;
import com.usian.common.aliyun.OSSService;
import com.usian.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.Map;

@RestController
public class TestController {

    @Autowired
    private GreenTextScan textScan;

    @Autowired
    private GreenImageScan imageScan;

    @Autowired
    private OSSService ossService;

    /**
     * 文本测试
     * @param text
     * @return
     * @throws Exception
     */
    @PostMapping("/text")
    public ResponseResult text(@RequestParam("text") String text) throws Exception {
        Map<String, String> map = textScan.greenTextScan(text);
        return ResponseResult.ok(map);
    }

    /**
     * 图片测试
     */
    @PostMapping("/image")
    public ResponseResult image(@RequestParam("file")MultipartFile file) throws Exception {
        String url = ossService.upload(file);
        Map<String, String> map = imageScan.imageScan(Arrays.asList(url));
        return ResponseResult.ok(map);
    }
}
